﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Eqwww.App.Authorize;

namespace Eqwww.Web.Controllers
{
    [Authorize]
    public class ManageController : Controller
    {
        private AuthorizeApp _authorizeApp;
        public ManageController(AuthorizeApp authorizeApp)
        {
            _authorizeApp = authorizeApp;
        }

       
        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Default()
        {
            return View();
        }

        public IActionResult GetAuthorizedMenus()
        {
            var data = _authorizeApp.GetAuthorizedMenus(User);

            var result = from p in data.Where(x=>x.ParentId==null)
                         select new
                         {
                             id = p.Id,
                             code = p.Code,
                             text = p.Name,
                             icon = p.Icon,
                             itemopen = p.Code.ToLower() == "tender",
                             children = from q in data.Where(x => x.ParentId == p.Id)
                                        select new
                                        {
                                            id = q.Id,
                                            code = q.Code,
                                            text = q.Name,
                                            icon = q.Icon,
                                            url = q.Url,
                                            closemark = true
                                        }
                         };

            return Json(result);
        }
    }
}